import { httpPost } from '@/appBase/request';
import { http, httpDel, httpGet, httpPut } from '@/appBase/request'
import { toDataForSys, toPageDataForSys, toPageQueryParam } from '@/appBase/utils'
import { toQueryParamForSys } from '@/modules/common/service/base';
import { toQueryString } from '@zkey-webapp/general';

// 查询角色列表
export function queryRoleList(queryParams, parameter) {
    const path = toQueryString({
        [encodeURIComponent('params[beginTime]')]:queryParams.beginTime,
        [encodeURIComponent('params[endTime]')]:queryParams.endTime,
    },`/system/role/list`);
    return httpGet(path,toPageQueryParam(queryParams, parameter)).then((result) =>toPageDataForSys(result,parameter));
}

// 查询角色详细
export function getRole(roleId) {
    return httpGet('/system/role/' + roleId).then((result) =>toDataForSys(result));
}

// 新增角色
export function addRole(data) {
    return httpPost('/system/role',data).then((result) =>toDataForSys(result));
}

// 修改角色
export function updateRole(data) {
    return httpPut('/system/role',data).then((result) =>toDataForSys(result));
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
    const data = {
        roleId,
        status
    }
    return httpPut('/system/role/changeStatus',data).then((result) =>toDataForSys(result));
}

// 删除角色
export function delRole(roleId) {
    return httpDel(`/system/role/${roleId}`).then((result) =>toDataForSys(result));
}

// 查询角色已授权用户列表
export function queryAllocatedUserList(queryParams, parameter) {
    return httpGet('/system/role/authUser/allocatedList',toPageQueryParam(queryParams, parameter)).then((result) =>toPageDataForSys(result,parameter));
}

// 查询角色未授权用户列表
export function queryUnallocatedUserList(queryParams, parameter) {
    return httpGet('/system/role/authUser/unallocatedList',toPageQueryParam(queryParams, parameter)).then((result) =>toPageDataForSys(result,parameter));
}

// 取消用户授权角色
export function authUserCancel(data) {
    return httpPut(`/system/role/authUser/cancel`,data).then((result) =>toDataForSys(result));
}

// 批量取消用户授权角色
export function authUserCancelAll(data) {
    return http({
        url: '/system/role/authUser/cancelAll',
        method: 'put',
        params: data
    }).then((result) =>toDataForSys(result));
}

// 授权用户选择
export function authUserSelectAll(data) {
    return httpPut(`/system/role/authUser/selectAll?${toQueryParamForSys(data)}`).then((result) =>toDataForSys(result));
}
